home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4614 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Hungarian notation
  5. Date: 30 Jan 1996 13:15:41 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4em1ptINNn1@keats.ugrad.cs.ubc.ca>
  8. References: <30C40F77.53B5@swsbbs.com> <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> <4e5k6o$aci@grid.direct.ca> <4ej0ds$sju@rational.rational.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4ej0ds$sju@rational.rational.com>,
  12. Bob Kitzberger <rlk@rational.com> wrote:
  13. >qjackson@direct.ca wrote:
  14. >: I use typedef primarily if I know that an underlying data type might
  15. >: change at some point in the future, and I want to have one central way
  16. >: of changing it.  [...]
  17. >...
  18. >: Data abstraction.
  19. >
  20. >That bears as much resemblance to data abstraction as McDonald's bears
  21. >to fine dining.  You are using the primitive language types, and only
  22. >in those special cases where you believe that a type will change do
  23. >you introduce an alias for the type name.  That is not abstraction.
  24.  
  25. I fully agree. The using typedef to define a new name for a primitive type like
  26. long or int is nothing more than an issue of aliasing.
  27.  
  28. Abstraction means more. The concept includes operations. Doing a typedef to
  29. rename an integer to something else doesn't hide the fact that the new type is
  30. still compatible with integers, and integer operators like '+', '-', '<<' and
  31. so on.
  32.  
  33. >The term "abstraction" means to emphasize the essential aspects and
  34. >de-emphasize the inessential -- i.e. the user of a module (ADT, package,
  35. >class, etc.) sees the abstraction, and you, the implementor of
  36. >the module/ADT/package/class, hide the inessential details.  One
  37. >of these inessential details is the primitive type (or types) that
  38. >make up the inner workings of your abstraction.
  39.  
  40. Right. To make a truly abstract data type for, say, time_t, one would have to
  41. hide the fact that it is an integer (the inessential aspect) and provide
  42. abstract operations for manipulating this type, such as functions to convert
  43. some other date breakdwon into time_t, for calculating the difference between
  44. two time_t's and such.
  45.  
  46. I still maintain my point that typedefs are not necessary for good coding in C.
  47. The aliasing for which they are useful can just as easily be accomplished with
  48. pre-processor macros.
  49.  
  50. I use them infrequently for managing complex types with greater ease.
  51. There arise situations in which pre-processor macros don't "cut it". For
  52. example,
  53.  
  54.     typedef int (* compfun_t)(void *, void *)
  55.  
  56. can't be done as a "#define compfun_t" macro. 
  57.  
  58. If you do
  59.  
  60.     #define compfun_t int (*)(void *, void *)
  61.  
  62. You can use "compfun_t" in a cast all right, but you can use it to define
  63. variables of type compfun_t, since for function types, the cast form and
  64. declaration form don't simply differ by the presence of an identifier on the
  65. right.
  66.  
  67. This is one case where it really behooves the C coder to avail himself of a
  68. typedef. :)
  69.  
  70. But I will keep on writing "struct foo *bar
  71. -- 
  72.  
  73.